package org.hk.kg.finance.stuclz.action;

import java.util.List;
import java.util.Map;

import org.hk.kg.TraceObject;
import org.hk.kg.db.DBServiceProxy;
import org.hk.kg.finance.FinanceConstants;
import org.hk.kg.finance.stuclz.service.IStuClzService;
import org.hk.kg.finance.stuclz.service.StuClzService;
import org.hk.kg.ui.KGUiContext;
import org.hk.kg.ui.ParamsStack;
import org.hk.kg.utils.Constants;
import org.hk.kg.web.BaseAction;


public class StuClzAction extends BaseAction{
	
	private IStuClzService stuClzServ = DBServiceProxy.getProxyClz(StuClzService.class);

	/**
	 * 创建新的班级
	 * @param stack
	 * @return
	 */
	public String newStuClz(ParamsStack stack)
	{
		return "new_stu_clz";
	}
	
	/**
	 * 删除班级信息
	 * @param stack
	 * @return
	 */
	public String delStuClz(ParamsStack stack)
	{
		Object delIds[] = stack.getValues("stuClzIds");
		if(delIds.length == 0)
		{
			KGUiContext.instance.error(Constants.COMMON_FAIL_WINDOW_TITLE,
					FinanceConstants.MSG_STUCLZ_LEAST_ONE);
			return None;
		}
		boolean delRlt = stuClzServ.deleteStuClasses(delIds);
		return "stu_clz_page";
	}
	
	/**
	 * 跳转到班级修改界面
	 * @param stack
	 * @return
	 */
	public TraceObject modifyStuClz(ParamsStack stack)
	{
		Object delIds[] = stack.getValues("stuClzIds");
		if(delIds.length != 1)
		{
			KGUiContext.instance.error(Constants.COMMON_FAIL_WINDOW_TITLE,
					FinanceConstants.MSG_STUCLZ_ONLY_ONE);
			return new TraceObject(None);
		}
		TraceObject trace = new TraceObject("modify_stu_clz",true);
		trace.setParams(stuClzServ.getStuClzById(Integer.valueOf(delIds[0].toString())));
		return trace;
	}
	
	/**
	 * 获取所有的班级信息
	 * @return
	 */
	public String getClasses() {
		StringBuffer sbf=new StringBuffer();
		List<Map> rlt = stuClzServ.query();
		for(Map m : rlt)
		{
			sbf.append("<tr>")
				.append("<td><input type=\"checkbox\" name=\"stuClzIds\" value=\"" + m.get("stuClzId") + "\"/></td>")
				.append("<td>" + m.get("stuClzName") + "</td>")
				.append("<td>" + Constants.CONFIG.getValue(FinanceConstants.CLZ_TYPE_CONSTANTS, m.get("stuClzType").toString()) + "</td>")
				.append("</tr>");
		}
		return sbf.toString();
	}
}
